<template>
  <div>

    <van-list
    :immediate-check="false"
  v-model:loading="loading"
  :finished="finished"
  finished-text="没有更多了"
  @load="onLoad"
>
<div class="left_list">
      <div class="list_item" v-for="item in users" :key="item.userInfo.uid">
        <div class="item_avar">
          <img :src="item.userInfo.smallPic">
          <van-icon name="checked" v-if="item.userInfo.isVip"  class="vip" size="16" color="#2d53d4"/>
        </div>
        <div class="item_text">
          <div class="name">
            {{ item.userInfo.nickname }}
          </div>
          <div style="color: #a3a3ac;" v-if="item.userInfo.pTtitle">{{ item.userInfo.pTtitle }}</div>
          <div class="item_icon">
            <div>
              <van-icon name="tv-o" />
              {{ item.statCountInfo.albumCount }}
            </div>
            <div>
              <van-icon name="bar-chart-o" />
              {{ item.userInfo.tracks_counts }}
            </div>
            <div>
              <van-icon name="user-o" />
              {{ item.userInfo.followers_counts }}
            </div>
          </div>
        </div>
      </div>

    </div>
</van-list>
    
  </div>
</template>

<script setup lang="ts">
import {onMounted, ref} from 'vue'

const loading = ref(false);
const finished = ref(false);
import {  reactive} from 'vue';
import searchApi from '@/apis/search'
import type {DetailModel,AnyObject} from '@/apis/search'
import {useRoute} from 'vue-router';
const route=useRoute();
let params=reactive<DetailModel>({
  kw:route.params.keyWord as string,
  core:'user',
  page:1,
  rows:20,
  condition:'relation',
});


// 获取主播信息函数
const users=ref<AnyObject[]>([]);
let totalPage=ref<number>();
const getAnchorData=async()=>{
  try {
    let res=await searchApi.reqSearchDetail(params);
    if(res.ret==0){
      totalPage.value=res.data.userViews.totalPage;
      if(params.page==totalPage.value){
        finished.value=true;
      }
      users.value.push(...res.data.userViews.users);
    }
  } catch (error) {
    console.log(error);
  }
};



const onLoad=async()=>{
  params.page++;
  await getAnchorData();
  loading.value=false;
};


defineExpose({
  users,
  getAnchorData,
  params
});

onMounted(()=>{
  getAnchorData();
})

</script>

<style lang="less" scoped>

.left_list {
  width: 100%;
  height: 100%;
  // margin-left: 20px;
  // background: antiquewhite;
   padding: 15px 0;
   padding-left: 10px;
   box-sizing: border-box;
}
.list_item {
  width: 100%;
  display: flex;
  border-bottom: 1px solid #f6f6f6;
  padding-bottom: 20px;
  margin-top: 20px;
 
  
}
.item_avar {
  width: 60px;
  height: 53px;
  position: relative;
  img{
    width: 50px;
    height: 50px;
    
  }
  .vip {
    position: absolute;
    top: 35px;
    left: 40px;
  }
}
.item_text{
font-size: 12px;
line-height: 20px;

}
.name {
  font-size: 16px;
  
}
.item_icon {
  display: flex;
  color: #a3a3ac;
  div {
    margin-right: 30px;
  }
}
</style>